from selenium import webdriver
import unittest,time

from selenium.webdriver.common.by import By

from unint_1.mysql import Mysql
class JiuXian(unittest.TestCase):
    def setUp(self):
        self.driver=webdriver.Edge()
        self.driver.get('http://10.59.9.14:7003/')
        self.driver.maximize_window()
        self.db=Mysql(host='10..59.9.14',user='root',password='yidong666',db='a3mall')

    def tearDown(self):
        time.sleep(10)
        self.driver.quit()
        self.db.close()
    def test_01_login(self):
        self.driver.find_element(By.LINK_TEXT, '登录').click()
        time.sleep(2)
        # 输入账号密码
        self.driver.find_element(By.NAME, 'username').send_keys('18986670716')
        self.driver.find_element(By.NAME, 'password').send_keys('a123456')
        time.sleep(10)
        # 点击登录按钮
        self.driver.find_element(By.CSS_SELECTOR, '.finish-btn').click()
        time.sleep(2)
        alldata=self.db.chaxun('select nickname from mall_users where mobie="18986670716"')
        print(alldata[0][0])
        # 搜索
        search=self.driver.find_element(By.CLASS_NAME,'search-input')
        search.send_keys('白云边')
        print(search.get_attribute('value'))
        time.sleep(3)

        self.driver.find_element(By.XPATH,'/html/body/div[5]/div[2]/div[2]/div[1]/ul/li[2]/div[1]/span/a/img').click()
        time.sleep(2)

        self.driver.find_element(By.ID,'buy-cart').click()
        time.sleep(5)



